//define(function(require,exports){
'use strict';

angular
    .module('mobileApp', [
        'ngRoute',
        'ngTouch',
        'ngAnimate',
        "ngSanitize"
    ])
    .config(["$routeProvider","$httpProvider",function ($routeProvider,$httpProvider) {
        $httpProvider.defaults.useXDomain = true;
        delete $httpProvider.defaults.headers
            .common['X-Requested-With'];
        $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
        $httpProvider.defaults.headers.put['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
        // Override $http service's default transformRequest
        $httpProvider.defaults.transformRequest = [function(data)
        {
            /**
             * The workhorse; converts an object to x-www-form-urlencoded serialization.
             * @param {Object} obj
             * @return {String}
             */
            var param = function(obj)
            {
                var query = '';
                var name, value, fullSubName, subName, subValue, innerObj, i;

                for(name in obj)
                {
                    value = obj[name];

                    if(value instanceof Array)
                    {
                        for(i=0; i<value.length; ++i)
                        {
                            subValue = value[i];
                            fullSubName = name + '[' + i + ']';
                            innerObj = {};
                            innerObj[fullSubName] = subValue;
                            query += param(innerObj) + '&';
                        }
                    }
                    else if(value instanceof Object)
                    {


                        for(subName in value)
                        {


                            subValue = value[subName];
                            if(subValue != null){
                                // fullSubName = name + '[' + subName + ']';
                                fullSubName = name + '.' + subName;
                                // fullSubName =  subName;
                                innerObj = {};
                                innerObj[fullSubName] = subValue;
                                query += param(innerObj) + '&';
                            }
                        }
                    }
                    else if(value !== undefined ) //&& value !== null
                    {
                        query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
                    }
                }


                return query.length ? query.substr(0, query.length - 1) : query;
            };


            return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
        }];

        $routeProvider
            .when('/', {
                // templateUrl: 'http://192.168.0.116:3000/demo/main/index.html',
                template:ui.main,
                controller: 'MainCtrl'
            })
            .when('/help', {
                templateUrl: 'main/help.html',
                controller: 'HelpCtrl'
            })
            .when('/auth', {
                templateUrl: 'main/auth.html',
                controller: 'AuthCtrl'
            })
            .when('/login', {
                templateUrl: 'main/login.html',
                controller: 'LoginCtrl'
            })
            .when('/mobile', {
                templateUrl: 'main/mobile.html',
                controller: 'MobileCtrl'
            })
            .when('/forget', {
                templateUrl: 'main/forget.html',
                controller: 'ForgetCtrl'
            })
            .when('/reg', {
                templateUrl: 'main/reg.html',
                controller: 'RegCtrl'
            })
            .otherwise({
                redirectTo: '/'
            });
    }]);
//});


var ui = {
    main:'<div class="g-hd">'+
    '    <div class="m-head g-fluid">'+
    '        <div class="g-xs2 f-tac"><a href="#/"class="logo">好觅<br />点餐</a></div>'+
    '        <div class="g-xs8"><form class="m-sch" name="js_search" ><input type="text" class="ipt"/><i class="icon-font" title="搜索">&#xe631;</i></form></div>'+
    '        <div class="g-xs2 f-tar" ng-bind-html="next"></div>'+
    '    </div>'+
    '</div>'+
    '<div class="g-ct">'+
    '    <div class="f-cb m-slides" ng-swipe-left="sildeLeft()" ng-swipe-right="sildeRight()">'+
    '        <div class="wrap" style="width:{{totalWidth}};margin-left:{{marginLeft}}">'+
    '            <div style="width:{{screenWidth}}" class="slide" ondragstart="return false" ng-repeat="ad in adList"><img ng-src="{{ad.imagePath}}  " alt=""/></div>'+
    '        </div>'+
    '        <div class="nav">'+
    '            <span ng-class="index==0? \'z-sel\' :\'\'"></span>'+
    '            <span ng-class="index==1? \'z-sel\' :\'\'"></span>'+
    '        </div>'+
    '    </div>'+
    '    <div class="m-fast g-container">'+
    '        <div class="g-xs6 item">'+
    '            <a href="shop.html">'+
    '                <i class="icon-font locator" title="美食">&#xe632;</i>'+
    '                美食雷达'+
    '            </a>'+
    '        </div>'+
    '        <div class="g-xs6 item">'+
    '            <a href="life.html">'+
    '                <i class="icon-font life" title="生活">&#xe633;</i>'+
    '                生活缴费'+
    '            </a>'+
    '        </div>'+
    '    </div>'+
    '    <div class="g-container m-ad">'+
    '        <div class="g-xs6 item" style="height:14.6rem;">'+
    '            <a href="">'+
    '                <div class="avatar"><img src="http://placehold.it/162x135/7ecdc5/fff" alt=""/></div>'+
    '                <p class="name s-red">好觅抢购</p>'+
    '                <p class="small">疯抢10元红包</p>'+
    '            </a>'+
    '        </div>'+
    '        <div class="g-xs6 item">'+
    '            <a href="">'+
    '                <div class="avatar"><img src="http://placehold.it/162x135/7ecdc5/fff" alt=""/></div>'+
    '                <p class="name">外卖周年庆</p>'+
    '                <p class="small">疯抢10元红包</p>'+
    '            </a>'+
    '        </div>'+
    '        <div class="g-xs6 item">'+
    '            <a href="">'+
    '                <div class="avatar"><img src="http://placehold.it/162x135/7ecdc5/fff" alt=""/></div>'+
    '                <p class="name">大牌代金卷</p>'+
    '                <p class="small">满50减5</p>'+
    '            </a>'+
    '        </div>'+
    '    </div>'+
    '    <div class="g-container m-ad">'+
    '        <div class="g-xs6 item">'+
    '            <a href="">'+
    '                <div class="avatar"><img src="http://placehold.it/162x135/7ecdc5/fff" alt=""/></div>'+
    '                <p class="name">大牌代金卷</p>'+
    '                <p class="small">满50减5</p>'+
    '            </a>'+
    '        </div>'+
    '        <div class="g-xs6 item">'+
    '            <a href="">'+
    '                <div class="avatar"><img src="http://placehold.it/162x135/7ecdc5/fff" alt=""/></div>'+
    '                <p class="name">大牌代金卷</p>'+
    '                <p class="small">满50减5</p>'+
    '            </a>'+
    '        </div>'+
    '    </div>'+
    '</div>'

}